﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using AvalonDock;
using SWCInvoice.ViewModel;

namespace SWCInvoice {
    /// <summary>
    /// Interaction logic for VirtualDocumentStructureView.xaml
    /// </summary>
    public partial class VirtualDocumentStructureView : UserControl {
        public VirtualDocumentStructureView() {
            InitializeComponent();
        }

        private void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            TreeView item = (TreeView)(sender);
            try {
                ((MainViewModel)this.DataContext).PdfViewViewModel.CurrentPage = ((Model.Page)item.SelectedItem);
            } catch (InvalidCastException castEx) { } 
              catch (Exception ex) {
                  if (this.DataContext != null) {
                      ((MainViewModel)this.DataContext).LoggingManager.AddMessage(new Model.Message(ex.Message, Enums.MessageTyp.Error, ex.StackTrace, ex.Source));
                      ((MainViewModel)this.DataContext).PdfViewViewModel.CurrentPage = null;
                  }
            }

        }  
    }
}
